<%@page import="com.alibaba.fastjson.JSONObject"%>
<%@page import="com.dingpeikeji.quickdeer.modules.base.web.FSysController"%>
<%@page import="com.dingpeikeji.quickdeer.core.common.utils.CookieUtils"%>
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="${ctxStatic }/index/register/css/register.css" rel="stylesheet">
<script src="${ctxStatic}/jquery/jquery-1.8.3.min.js" type="text/javascript"></script>
<script src="${ctxStatic}/jquery/jquery.validate.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
    //Default Action
    $(".tab_content").hide(); //Hide all content
    $("ul.tabs li:first").addClass("active").show(); //Activate first tab
    $(".tab_content:first").show(); //Show first tab content
    //On Click Event
    $("ul.tabs li").click(function() {
        $("ul.tabs li").removeClass("active"); //Remove any "active" class
        $(this).addClass("active"); //Add "active" class to selected tab
        $(".tab_content").hide(); //Hide all tab content
        var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
        $(activeTab).fadeIn(); //Fade in the active content
        return false;
    });
    $("#btn").attr("disabled", true); 
    $("#btn2").attr("disabled", true); 
    $("#subBtn").attr("disabled", true); 
    $("#subBtn2").attr("disabled", true); 
	var keyVal2 = "${sessionScope.mes}";
	if(keyVal2.length!=0){  
		alert(keyVal2);
	}
	$("input[name='mobile']").blur(function(){
		//获取输入的值
		var $value=$(this).val();
		if($value.length!=0){  
		$.post("${ctxFront}/sms/checkTel","mobile="+$value,function(d){
			//alert(d);
			if(d==1){
				$("#mobilTip").html("<font color='green'>手机号可以使用</font>");
			}else if(d==0){
				$("#mobilTip").html("<font color='red'>手机号已被使用</font>");
			}else if(d==2){
				$("#mobilTip").html("<font color='red'>手机号码格式不正确</font>");
			}
		});
		}
	});
	$("input[name='mobile2']").blur(function(){
		//获取输入的值
		var $value=$(this).val();
		if($value.length!=0){  
		$.post("${ctxFront}/sms/checkTel","mobile="+$value,function(d){
			//alert(d);mobil2Tip
			if(d==1){
				$("#mobil2Tip").html("<font color='green'>手机号可以使用</font>");
			}else if(d==0){
				$("#mobil2Tip").html("<font color='red'>手机号已被使用</font>");
			}else if(d==2){
				$("#mobil2Tip").html("<font color='red'>手机号码格式不正确</font>");
			}
		});
		}
	});
	$("input[name='confirmNewPassword']").blur(function(){
		//获取输入的值
		var $password1=$("#newPassword").val();
		var $password2=$(this).val();
		if($password1.length!=0 && $password2.length!=0){  
			$.post("${ctxFront}/sms/checkPassword",{"password1":$password1,"password2":$password2},function(d){
				if(d==0){
					$("#confirmTip").html("<font color='red'>两次输入的密码不一致</font>");
					$("#newPassword").click(function(){
						$("#confirmNewPassword").val("");
					})
				}else if(d==1){
					$("#confirmTip").html("<font color='red'>6-16位数字和字母的组合</font>");
					$("#newPassword").click(function(){
						$("#confirmNewPassword").val("");
					})
				}else if(d==2){
					$("#confirmTip").html("<font color='green'>可以使用</font>");
					$('#btn').removeAttr('disabled');
					var $value=$("input[name='mobile']").val();
					$("#btn").click(function(){
						$.post('${ctxFront}/sms/send', {"phone":$value,"type":0},function(data) {
							if (data != 'success') {
								alert(data);
							} 
						});
							$('#subBtn').removeAttr('disabled');
					});
				}
			});
		}
	});
	$("input[name='confirmNewPassword2']").blur(function(){
		//获取输入的值
		var $password3=$("#UserPass").val();
		var $password4=$(this).val();
		if($password3.length!=0 && $password4.length!=0){  
			$.post("${ctxFront}/sms/checkPassword",{"password1":$password3,"password2":$password4},function(d){
				if(d==0){
					$("#t_RePassTip").html("<font color='red'>两次输入的密码不一致</font>");
					$("#UserPass").click(function(){
						$("#RePass").val("");
					})
				}else if(d==1){
					$("#t_RePassTip").html("<font color='red'>6-16位数字和字母的组合</font>");
					$("#UserPass").click(function(){
						$("#RePass").val("");
					})
				}else if(d==2){
					$("#t_RePassTip").html("<font color='green'>可以使用</font>");
					$('#btn2').removeAttr('disabled');
					var $value=$("input[name='mobile2']").val();
					$("#btn2").click(function(){
						$.post('${ctxFront}/sms/send', {"phone":$value,"type":0},function(data) {
							if (data != 'success') {
								alert(data);
							} 
						});
							$('#subBtn2').removeAttr('disabled');
					});
				}
			});
		}
	});
    $("#registerForm").validate({
		rules: {
			mobile:{
				required: true,
			},
			validateCode: {
				required: true,
			},
			newPassword :"required",
			confirmNewPassword :"required"
		},
		messages: {
			mobile: {
				required: "",
			},
			validateCode: {
				required: "",
			},
			newPassword: {
				required: "",
			},
			confirmNewPassword: {
				required: "",
			}
		},
		//提交表单后，（第一个）未通过验证的表单获得焦点  
        focusInvalid:true,  
        //当未通过验证的元素获得焦点时，移除错误提示  
        focusCleanup:true,
	});
    $("#registerForm2").validate({
		rules: {
			officeName:{
				required: true,
			},
			name: {
				required: true,
			},
			mobile2 :"required",
			validateCode2 :"required",
			newPassword2 :"required",
			confirmNewPassword2 :"required"
		},
		messages: {
			officeName: {
				required: "",
			},
			name: {
				required: "",
			},
			mobile2: {
				required: "",
			},
			validateCode2: {
				required: "",
			},
			newPassword2: {
				required: "",
			},
			confirmNewPassword2: {
				required: "",
			}
		},
		//提交表单后，（第一个）未通过验证的表单获得焦点  
        focusInvalid:true,  
        //当未通过验证的元素获得焦点时，移除错误提示  
        focusCleanup:true,
	});
});
	var countdown = 120;
	function settime(obj) {
		if (countdown == 0) {
			obj.removeAttribute("disabled");
			obj.value = "发送";
			countdown = 120;
			return;
		} else {
			obj.setAttribute("disabled", true);
			obj.value = "重发(" + countdown + ")";
			countdown--;
		}
		setTimeout(function() {
			settime(obj)
		}, 1000)
	};
	function settime2(obj) {
		if (countdown == 0) {
			obj.removeAttribute("disabled");
			obj.value = "发送";
			countdown = 120;
			return;
		} else {
			obj.setAttribute("disabled", true);
			obj.value = "重发(" + countdown + ")";
			countdown--;
		}
		setTimeout(function() {
			settime2(obj)
		}, 1000)
	};
	function subRegisterForm() {
		if (!$('#agreementInfo1').is(':checked')) {
			alert('请先同意《霞客约车网服务协议》！');
			return;
		}
		$('#registerForm').submit();
	}
	function subRegisterForm2() {
		if (!$('#agreementInfo2').is(':checked')) {
			alert('你还未同意《霞客约车网服务协议》！');
			return false;
		} else {
			$('#registerForm2').submit();
		}
	}
</script>
<script>
	//第一种方法
	$(document)
			.ready(
					function() {
						var doc = document, inputs = doc
								.getElementsByTagName('input'), supportPlaceholder = 'placeholder' in doc
								.createElement('input'), placeholder = function(
								input) {
							var text = input.getAttribute('placeholder'), defaultValue = input.defaultValue;
							if (defaultValue == '') {
								input.value = text
							}
							input.onfocus = function() {
								if (input.value === text) {
									this.value = ''
								}
							};
							input.onblur = function() {
								if (input.value === '') {
									this.value = text
								}
							}
						};
						if (!supportPlaceholder) {
							for (var i = 0, len = inputs.length; i < len; i++) {
								var input = inputs[i], text = input
										.getAttribute('placeholder');
								if (input.type === 'text' && text) {
									placeholder(input)
								}
							}
						}
					});
</script>
<title>注册</title>
	<%
session.removeAttribute("mes");
	%>
</head>
<body>
	<div class="register">
		<div class="register1">
			<a href="${ctxFront}/index"><img class="img-1" src="${ctxStatic }/index/images/logo.png"></a>
			<img class="phone" src="${ctxStatic }/index/images/phone.png">
		</div>
	</div>
	<div class="over">
		<div class="d_chr">
			<div class="num">
				<p class="hree">欢迎注册</p>
				<dl>
					<dd class="d_null">
						<span class="numble">已有账号，</span>
						<a href="${pageContext.request.contextPath }/login.jsp" class="numble-1">立即登录》</a>
					</dd>
				</dl>
			</div>
			<div id="back">
				<div class="reg-left"><font color='red' size='4'>${message}</font> 
					<ul class="tabs">
						<li class="active"><a href="#tab1">个人</a></li>
						<li><a href="#tab4">单位</a></li>
					</ul>
					<div class="reg">
						<div id="tab1" class="tab_content" style="display: block;">
							<form action="${ctxFront}/doregister" method="post" id="registerForm" style="display: block" >
								<dl>
									<dd>
										<span class="title">手机号码：</span>
										<input class="reg_input requied"
											name="mobile" id="mobile1" placeholder="请输入手机号码"
											type="text" />
											<span id="mobilTip" class="onshow"></span>
									</dd>
									<dd>
										<span class="title">输入密码：</span>
										<input class="reg_input"
											id="newPassword"
											name="newPassword"  type="password" placeholder="6-16位数字和字母的组合"/>
											<span id="newPasswordTip" class="onshow"></span>
									</dd>
									<dd>
										<span class="title">确认密码：</span>
										<input
											class="reg_input"
											type="password" id="confirmNewPassword" name="confirmNewPassword"
											placeholder="6-16位数字和字母的组合" />
								<span id="confirmTip" class="onshow"></span>
									</dd>
									<dd>
										<span class="title">验证码：</span>
										<input id="t_CheckCode"
											class="reg_input_pic" name="validateCode" placeholder="请输入验证码"
											type="text" maxlength="4" />
										<input type="text" id="btn" class="obtain" value="发送" onclick="settime(this)"/> 
										<span id="codeTip" class="onshow"></span>
									<dd>
									<dd class="d_chenk">
										<input type="checkbox" class="Sex_Man" name="rb_Sex" id="agreementInfo1"
										checked="checked"	/>同意，
											<a href="${pageContext.request.contextPath }/webInfo.jsp?id=xz" class="protoco" target=_blank
											style="color: #5dc4a4">《霞客约车服务协议》</a>
									</dd>
								</dl>
								<input type="text" class="protocol1" id="subBtn" onclick="subRegisterForm()" value="同意协议并注册">
							</form>
						</div>
						<div class="reg">
							<div id="tab4" class="tab_content" style="display: none;">
								<form action="${ctxFront}/doregister" method="post" id="registerForm2">
								<input type="hidden" name="userType" value="1"/>
									<dl>
										<dd>
											<span class="title">单位名称：</span>
											<input class="reg_input" name="officeName" placeholder="请输入贵公司名称">
											<span id="mobilTip" class="onshow"></span>
										</dd>
										<dd>
											<span class="title">经办人姓名：</span>
											<input class="reg_input" name="name" placeholder="请输入你的姓名"/>
											<span id="mobilTip" class="onshow"></span>
										<dd>
											<span class="title">手机号码：</span>
											<input class="reg_input"
												 id="mobile2" name="mobile2" placeholder="请输入手机号码"
												type="text" />
												<span id="mobil2Tip" class="onshow"></span>
										</dd>
										<dd>
											<span class="title">输入密码：</span>
											<input class="reg_input" name="newPassword2" id="UserPass"  placeholder="请输入密码" type="password" />
												<span id="t_UserPassTip" class="onshow"></span>
										</dd>
										<dd>
											<span class="title">确认密码：</span>
											<input class="reg_input" type="password" id="RePass" name="confirmNewPassword2" placeholder="请确认密码" />
											<span id="t_RePassTip" class="onshow"></span>
										</dd>
										<dd>
											<span class="title">验证码：</span>
											<input id="CheckCode" class="reg_input_pic" name="validate2"
												placeholder="请输入验证码" type="text" maxlength="4" />
											<input type="text" id="btn2" class="obtain" value="发送" onclick="settime2(this)"/> 
											<span id="mobilTip" class="onshow"></span>
										<dd>
									</dl>
									<dl>
									<dd class="d_chenk">
										<input type="checkbox" class="Sex_Man" name="rb_Sex" id="agreementInfo2"
											checked="CHECKED" />同意，
											<a href="${pageContext.request.contextPath }/webInfo.jsp?id=xz" class="protoco" target=_blank
											style="color: #5dc4a4">《霞客约车服务协议》</a>
									</dd>
								</dl>
									<input type="text" class="protocol1" id="subBtn2" onclick="subRegisterForm2()" value="同意协议并注册">
								</form>
							</div>
						</div>
					</div>
				</div>
				<jsp:include page="why.jsp"></jsp:include>
			</div>
		</div>
	</div>
	<jsp:include page="/WEB-INF/views/layouts/foot.jsp"></jsp:include>
</body>
</html>